package com.gzy.rpsm.property.utils;

public class StringUtil {
    /**
     * 从输入的字符串中提取所有的数字字符，并将它们组合成一个新的字符串，最后将这个新字符串转换为整数返回
     * @param str
     * @return
     */
    public static int getNumberFromString(String str){
        char[] chars = str.toCharArray();
        StringBuilder builder = new StringBuilder();
        for (char c:chars) {
            if(c >= '0' && c <= '9'){
                builder.append(c);
            }
        }
        return Integer.valueOf(builder.toString());
    }

    public static String numberToLen2String(int i) {
        if (-1 < i && i < 10) {
            return "0" + i;
        } else {
            return i + "";
        }
    }

    public static Integer stringPriceToInt(String price) throws Exception{
        if(price != null){
            try{
                Double d = Double.valueOf(price);
                return Double.valueOf(d * 100).intValue();
            }catch (NumberFormatException e){
                throw new Exception("不是浮点数格式");
            }
        }
        return null;
    }
}
